/*
 * 娉ㄦ剰锛�
 * 1. 鎵€鏈夌殑JS鎺ュ彛鍙兘鍦ㄥ叕浼楀彿缁戝畾鐨勫煙鍚嶄笅璋冪敤锛屽叕浼楀彿寮€鍙戣€呴渶瑕佸厛鐧诲綍寰俊鍏紬骞冲彴杩涘叆鈥滃叕浼楀彿璁剧疆鈥濈殑鈥滃姛鑳借缃€濋噷濉啓鈥淛S鎺ュ彛瀹夊叏鍩熷悕鈥濄€�
 * 2. 濡傛灉鍙戠幇鍦� Android 涓嶈兘鍒嗕韩鑷畾涔夊唴瀹癸紝璇峰埌瀹樼綉涓嬭浇鏈€鏂扮殑鍖呰鐩栧畨瑁咃紝Android 鑷畾涔夊垎浜帴鍙ｉ渶鍗囩骇鑷� 6.0.2.58 鐗堟湰鍙婁互涓娿€�
 * 3. 瀹屾暣 JS-SDK 鏂囨。鍦板潃锛歨ttp://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
 *
 * 濡傛湁闂璇烽€氳繃浠ヤ笅娓犻亾鍙嶉锛�
 * 閭鍦板潃锛歸eixin-open@qq.com
 * 閭欢涓婚锛氥€愬井淇S-SDK鍙嶉銆戝叿浣撻棶棰�
 * 閭欢鍐呭璇存槑锛氱敤绠€鏄庣殑璇█鎻忚堪闂鎵€鍦紝骞朵氦浠ｆ竻妤氶亣鍒拌闂鐨勫満鏅紝鍙檮涓婃埅灞忓浘鐗囷紝寰俊鍥㈤槦浼氬敖蹇鐞嗕綘鐨勫弽棣堛€�
 */
wx.ready(function () {
  // 2. 鍒嗕韩鎺ュ彛
  // 2.1 鐩戝惉鈥滃垎浜粰鏈嬪弸鈥濓紝鎸夐挳鐐瑰嚮銆佽嚜瀹氫箟鍒嗕韩鍐呭鍙婂垎浜粨鏋滄帴鍙�
  document.querySelector('#onMenuShareAppMessage').onclick = function () {
    wx.onMenuShareAppMessage({
      title: '算的准',
      desc: '你从未见过的占卜方式',
      link: 'http://www.ccian.com/oauth2/oauth',
      imgUrl: 'http://otooldst4.bkt.clouddn.com/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20170825141352.jpg',
      trigger: function (res) {
        // 涓嶈灏濊瘯鍦╰rigger涓娇鐢╝jax寮傛璇锋眰淇敼鏈鍒嗕韩鐨勫唴瀹癸紝鍥犱负瀹㈡埛绔垎浜搷浣滄槸涓€涓悓姝ユ搷浣滐紝杩欐椂鍊欎娇鐢╝jax鐨勫洖鍖呬細杩樻病鏈夎繑鍥�
        alert('鐢ㄦ埛鐐瑰嚮鍙戦€佺粰鏈嬪弸');
      },
      success: function (res) {
        alert('你从未见过的占卜方式');
      },
      cancel: function (res) {
        alert('算的准�');
      },
      fail: function (res) {
        alert(JSON.stringify(res));
      }
    });
    alert('宸叉敞鍐岃幏鍙栤€滃彂閫佺粰鏈嬪弸鈥濈姸鎬佷簨浠�');
  };

  // 2.2 鐩戝惉鈥滃垎浜埌鏈嬪弸鍦堚€濇寜閽偣鍑汇€佽嚜瀹氫箟鍒嗕韩鍐呭鍙婂垎浜粨鏋滄帴鍙�
  document.querySelector('#onMenuShareTimeline').onclick = function () {
    wx.onMenuShareTimeline({
      title: '算得准',
      link: 'http://www.ccian.com/oauth2/oauth',
      imgUrl: 'http://otooldst4.bkt.clouddn.com/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20170825141352.jpg',
      trigger: function (res) {
        // 涓嶈灏濊瘯鍦╰rigger涓娇鐢╝jax寮傛璇锋眰淇敼鏈鍒嗕韩鐨勫唴瀹癸紝鍥犱负瀹㈡埛绔垎浜搷浣滄槸涓€涓悓姝ユ搷浣滐紝杩欐椂鍊欎娇鐢╝jax鐨勫洖鍖呬細杩樻病鏈夎繑鍥�
        alert('鐢ㄦ埛鐐瑰嚮鍒嗕韩鍒版湅鍙嬪湀');
      },
      success: function (res) {
        alert('宸插垎浜�');
      },
      cancel: function (res) {
        alert('宸插彇娑�');
      },
      fail: function (res) {
        alert(JSON.stringify(res));
      }
    });
    alert('宸叉敞鍐岃幏鍙栤€滃垎浜埌鏈嬪弸鍦堚€濈姸鎬佷簨浠�');
  };

 


  var shareData = {
    title: '',
    desc: '',
    link: 'http://demo.open.weixin.qq.com/jssdk/',
    imgUrl: 'http://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRt8Qia4lv7k3M9J1SKqKCImxJCt7j9rHYicKDI45jRPBxdzdyREWnk0ia0N5TMnMfth7SdxtzMvVgXg/0'
  };
  wx.onMenuShareAppMessage(shareData);
  wx.onMenuShareTimeline(shareData);

  function decryptCode(code, callback) {
    $.getJSON('/jssdk/decrypt_code.php?code=' + encodeURI(code), function (res) {
      if (res.errcode == 0) {
        codes.push(res.code);
      }
    });
  }
});

wx.error(function (res) {
  alert(res.errMsg);
});
